﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.Mod.Groups
{
    using SharingCenter.Web.Classes;
    using SharingCenter.Web.Classes.enums;
    using SharingCenter.Web.Classes.Groups;
    public partial class Members : GroupsPageBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ParseGroupIdFromQueryString();
            HasRights(groupId, Profile.UserId);
            ListView1.ItemDataBound += new EventHandler<ListViewItemEventArgs>(ListView1_ItemDataBound);
            SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.SiteMap_SiteMapResolve);
        }

        void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            ListView mbrlst = (ListView)e.Item.FindControl("lvMemberList");
            BindGroupMemberList(ref mbrlst);
        }

        void BindGroupMemberList(ref ListView mbrlst)
        {
            mbrlst.DataSource = dataContext.GetGroupMembers(groupId);
            mbrlst.DataBind();
        }

        protected void lblVisitDate_PreRender(object sender, EventArgs e)
        {
            Label lastVisitDate = (Label)sender;
            lastVisitDate.Text = Utility.FriendlyDateTime(lastVisitDate.Text, TimeDisplayEnum.LiteralHoursNoTimeInOtherDays, false);
        }

        protected void Page_Unload(object sender, EventArgs e)
        {
            SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(this.SiteMap_SiteMapResolve);
        }

        private SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
        {
            SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
            SiteMapNode tmpNode = currentNode.ParentNode;
            tmpNode.Title = group.GroupName;
            tmpNode.Url += "?id=" + groupId;
            return currentNode;
        }

    }
}
